package ch.bfh.java.directorysynchronizer.presentation.Frame;

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import ch.bfh.java.directorysynchronizer.presentation.actionlisteners.LogfileDirectoryButtonListener;
import ch.bfh.java.directorysynchronizer.presentation.actionlisteners.SourcefileDirectoryButtonListener;
import ch.bfh.java.directorysynchronizer.presentation.actionlisteners.TargetfileDirectoryButtonListener;
import ch.bfh.java.directorysynchronizer.presentation.items.Workbench;

public class ChooseADirectoryPanel extends JPanel
{

	/**
     * 
     */
	private static final long serialVersionUID = 1L;

	private Workbench workbench;

	public ChooseADirectoryPanel(Workbench wb)
	{

		this.workbench = wb;

		this.setPreferredSize(workbench.getChooseDirectoryDimension());
		this.setLayout(new FlowLayout());

		/*
		 * first row
		 */
		this.add(new SourceDirectoryPanel());

		/*
		 * second row
		 */
		this.add(new TargetDirectoryPanel());

		/*
		 * third row
		 */
		this.add(new LogfileDirectoryPanel());

	}

	/*
	 * *******************************************************
	 */
	private class SourceDirectoryPanel extends JPanel
	{
		/**
         * 
         */
		private static final long serialVersionUID = 1L;
		private JLabel source;
		private JButton selectSourceDirectoryButton;

		private SourceDirectoryPanel()
		{
			this.setPreferredSize(new Dimension(workbench.getMainframewidth(),
			        (workbench.getChooseDirectoryPanelHeight() / 3)));

			this.source = new JLabel(" Source directory");
			this.add(this.source);
			
			workbench.getSourceDirectoryTextfield().setPreferredSize(new Dimension(300,25));
			workbench.getSourceDirectoryTextfield().setEditable(false);
			
			this.add(workbench.getSourceDirectoryTextfield());

			this.selectSourceDirectoryButton = new JButton("...");
			this.selectSourceDirectoryButton.addActionListener(new SourcefileDirectoryButtonListener(workbench));
			this.add(selectSourceDirectoryButton);
		}
	}

	/*
	 * ******************************************************************
	 */
	private class TargetDirectoryPanel extends JPanel
	{
		/**
         * 
         */
		private static final long serialVersionUID = 1L;
		private JLabel target;
		private JButton selectTargetDirectoryButton;

		private TargetDirectoryPanel()
		{
			this.setPreferredSize(new Dimension(workbench.getMainframewidth(),
			        (workbench.getChooseDirectoryPanelHeight() / 3)));

			this.target = new JLabel(" Target directory");
			this.add(this.target);

			workbench.getTargetDirectoryTextfield().setPreferredSize(new Dimension(300,25));
			workbench.getTargetDirectoryTextfield().setEditable(false);
			
			this.add(workbench.getTargetDirectoryTextfield());

			this.selectTargetDirectoryButton = new JButton("...");
			this.selectTargetDirectoryButton.addActionListener(new TargetfileDirectoryButtonListener(workbench));
			this.add(selectTargetDirectoryButton);
		}
	}

	/*
	 * *********************************************************************
	 */

	private class LogfileDirectoryPanel extends JPanel
	{
		/**
         * 
         */
		private static final long serialVersionUID = 1L;
		private JLabel logfiletarget;
		private JButton selectLogfileDirectoryButton;

		private LogfileDirectoryPanel()
		{
			this.setPreferredSize(new Dimension(workbench.getMainframewidth(),
			        (workbench.getChooseDirectoryPanelHeight() / 3)));

			this.logfiletarget = new JLabel(" Logfile location");
			this.add(this.logfiletarget);

			workbench.getLogfileDirectoryTextfield().setPreferredSize(new Dimension(300,25));


			this.add(workbench.getLogfileDirectoryTextfield());

			this.selectLogfileDirectoryButton = new JButton("...");
			this.selectLogfileDirectoryButton.addActionListener(new LogfileDirectoryButtonListener(workbench));
			this.add(selectLogfileDirectoryButton);
		}
	}
}
